from django.utils.deprecation import MiddlewareMixin

## 中间件
class TestMiddleWare(MiddlewareMixin):

    def process_request(self, request):
        username = request.COOKIES.get('username')
        if username is None:
            print("没有登录")
        else:
            print("已经登录")
        print("每次请求前调用执行")
    def process_response(self, request, response):
        print("每次响应前调用执行")
        return response
